package com.wuseguang.springcloud.controller;


import com.wuseguang.springcloud.Filter.RequestParameterWrapper;
import com.wuseguang.springcloud.entity.EvaluationModel;
import com.wuseguang.springcloud.service.EvaluationModelService;
import com.wuseguang.springcloud.util.Result;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 评价模型表 前端控制器
 * </p>
 *
 * @author 
 * @since 2020-02-12
 */
@RestController
@RequestMapping("/evaluationModel")
public class EvaluationModelController {

    private Logger logger = LoggerFactory.getLogger(this.getClass());
    @Autowired
    private EvaluationModelService evaluationModelServiceImpl;

    /**
     * 添加评价模型
     * @param request
     * @param evaluationModel
     * @return
     */
    @RequestMapping("/addEvaluationModel")
    public Result addEvaluationModel(RequestParameterWrapper request, EvaluationModel evaluationModel){
        logger.info("添加评价模型 EvaluationModelController -> addEvaluationModel");
        //学校id
        String schoolId = request.getParam("schoolId");
        //教师id
        String teacherId = request.getParam("teacherId");

        //赋值
        evaluationModel.setTeacherId(Integer.valueOf(teacherId));
        evaluationModel.setSchoolId(Integer.valueOf(teacherId));

        return evaluationModelServiceImpl.addEvaluationModel(evaluationModel);
    }

    /**
     * 查询教师自己创建的模型
     * @param request
     * @return
     */
    @RequestMapping("/findEvaluationModel")
    public Result findEvaluationModel(RequestParameterWrapper request){
        logger.info("查询教师自己创建的模型 EvaluationModelController -> finEvaluationModel");
        //教师id
        String teacherId = request.getParam("teacherId");

        return evaluationModelServiceImpl.findEvaluationModel(teacherId);
    }

    /**
     * 删除评价模型
     * @param request
     * @param id 模型id
     * @return
     */
    @RequestMapping("/deleteEvaluationModel")
    public Result deleteEvaluationModel(RequestParameterWrapper request,@RequestParam("id") Integer id){

        logger.info("删除评价模型 EvaluationModelController -> deleteEvaluationModel");

        return evaluationModelServiceImpl.deleteEvaluationModel(id);
    }

    /**
     * 修改评价模型
     * @param request
     * @param evaluationModel
     * @return
     */
    @RequestMapping("/updateEvaluationModel")
    public Result updateEvaluationModel(RequestParameterWrapper request, EvaluationModel evaluationModel){
        //教师id
        String schoolId = request.getParam("schoolId");
        //教师id
        String teacherId = request.getParam("teacherId");
        evaluationModel.setSchoolId(Integer.valueOf(schoolId));
        evaluationModel.setTeacherId(Integer.valueOf(teacherId));
        return evaluationModelServiceImpl.updateEvaluationModel(evaluationModel);
    }
}

